home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3088 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: news.gate.net!pslfl2-48
  2. From: bhutto@gate.net (William Hutto)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Printing to LPT1 Printer from within program
  5. Followup-To: comp.lang.c
  6. Date: 25 Jan 1996 16:07:56 GMT
  7. Organization: CyberGate, Inc.
  8. Message-ID: <4e89ss$1mns@news.gate.net>
  9. References: <4e5ee9$m28_001@pr.mcs.net>
  10. NNTP-Posting-Host: pslfl2-48.gate.net
  11. X-Newsreader: News Xpress Version 1.0 Beta #4
  12.  
  13. In article <4e5ee9$m28_001@pr.mcs.net>,
  14.    mdp@mika-sys.com (Michael D. Perry) spake:
  15. ;I have just started taking a C programming class and am using Borland 
  16. ;C++ v4.0 at home.  Both my teacher and I are stumped as to how to 
  17. ;print to a LPT (Line Printer) device from within the program.
  18. ;
  19. ;I have read the FAQ and there are some references to this but not 
  20. ;enough that I can quite figure it out.  As near as I can figure you 
  21. ;can use iostreams or fprintf() with the later appearing to be the 
  22. ;simpler of the two.  With that, from what I have seen, one uses a 
  23. ;filename of stdprn but I get an error message when compiling.  My 
  24. ;guess is that there is a header file or a definition/declaration 
  25. ;statement that needs to be referenced.
  26. ;
  27. ;In Pascal the Function LPrint() does this job quite nicely but I can 
  28. ;find no suitable similar function in my reference manuals.  Can anyone 
  29. ;help with the appropriate function(s) and perhaps some examples of 
  30. ;them in source code?
  31. ;
  32. ;I have looked at lots of materials on the Internet, quite a few books, 
  33. ;and hours in the on-line help and manuals for Borland C++ without 
  34. ;finding anything much about this.  So either I am incredibly stupid 
  35. ;because the answer is so obvious that no one writes about it or it is 
  36. ;a little more obscure and someone maybe should write it into an FAQ?
  37. ;
  38. ;Thanks in advance;
  39. ;
  40. ;Mike
  41.  
  42. You didn't play pro football did you? Anyway, with DOS, you are given 
  43. an open file to the standard printer at the start of your program. You can 
  44. usually access this file in C with the predefined 'stdprn' FILE * in 
  45. <stdio.h>, used thusly:
  46.  
  47.     fprintf(stdprn,"Send this line to the standard printer.\n");
  48.     
  49. If for some reason 'LPT1' were not the stdprn, you could still open it like a 
  50. file in DOS:
  51.  
  52. FILE *lpt1;
  53.  
  54.     if((lpt1=fopen("LPT1","w"))==NULL) {
  55.         /*error*/
  56.     }
  57.     fprintf(lpt1,"Send this line to LPT1.\n");
  58.  
  59. or you can reopen stdprn when it's not the printer you want:
  60.  
  61.     if(!freopen("LPT2","w",stdprn)) {
  62.         /*error*/
  63.     }
  64.     fprintf(stdprn,"This line definitely goes to LPT2.\n");
  65.  
  66. or even redirect stdout:
  67.  
  68.     if(!freopen("LPT1","w",stdout)) {
  69.         /*error*/
  70.     }
  71.     printf("This line goes to LPT1.\n");
  72.  
  73.     if(!freopen("CON","w",stdout)) {
  74.         /*error*/
  75.     }
  76.     printf("This line goes to screen.\n");
  77.  
  78.  
  79. Regards,
  80. Bill
  81.  
  82. William Hutto
  83. bhutto@gate.net
  84. N4YMN
  85.  
  86. "Whatcha got on?...Your mind?"
  87.